
matrix orthoProjMatrix;
float3x4 transformMatrix;

float4 viewportSize;

texture imageTexture;

sampler imageSampler = sampler_state
{
	Texture = <imageTexture>;
	AddressU = CLAMP;
	AddressV = CLAMP;
	AddressW = CLAMP;
	BorderColor = float4(0, 0, 0, 0);
	MipFilter = LINEAR;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
};

struct VertexShaderInput
{
	float3 position : POSITION0;
	float4 color : COLOR0;
	float2 texCoord : TEXCOORD0;
};

struct PixelShaderInput
{
	float4 position : POSITION0;
	float2 texCoord : TEXCOORD0;
	float4 color : TEXCOORD1;
};

void VertexMain(in VertexShaderInput vsInput, out PixelShaderInput output)
{
	output = (PixelShaderInput)0;

	float3 newPosTransform = mul(float3(vsInput.position.xy, 1), float3x3(transformMatrix._11_12_13, transformMatrix._21_22_23, transformMatrix._31_32_33));
	newPosTransform.xy /= newPosTransform.z;

	float4 posTransformed = float4(newPosTransform.xy, 0, 1);

	float xbase = -viewportSize.x / 2.0f;
	float ybase = viewportSize.y / 2.0f;
	posTransformed.x += xbase;
	posTransformed.y = ybase - posTransformed.y;

	output.position = mul(float4(posTransformed.xy, 0, 1), orthoProjMatrix);
	output.position.x -= 1.0f / (2 * viewportSize.x);
	output.position.y -= 1.0f / (2 * viewportSize.y);
	output.texCoord = vsInput.texCoord;
	output.color = vsInput.color;
}

void PixelMain(in PixelShaderInput input, out float4 color : COLOR0)
{
	color = tex2D(imageSampler, input.texCoord);
}